package cn.usian.product.service.impl;

import cn.usian.jyzx.model.dto.h5.ProductSkuDto;
import cn.usian.jyzx.model.entity.product.Product;
import cn.usian.product.mapper.ProductMapper;
import cn.usian.product.service.ProductService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ProductServiceImpl extends ServiceImpl<ProductMapper, Product> implements ProductService {
    @Override
    public List<Product> findByPage(ProductSkuDto dto) {
        /*
            按条件分页查询
            准备一个分页对象和查询条件,然后调用mapper中的方法即可
         */
        LambdaQueryWrapper<Product> like = Wrappers.lambdaQuery(Product.class).
                like(dto.getKeyword() != null && dto.getKeyword().trim().length() > 0, Product::getName, dto.getKeyword()).
                eq(dto.getCategory1Id()!=null,Product::getCategory1Id,dto.getCategory1Id()).
                eq(dto.getCategory2Id()!=null,Product::getCategory2Id,dto.getCategory2Id()).
                eq(dto.getCategory3Id()!=null,Product::getCategory3Id,dto.getCategory3Id()).
                eq(Product::getStatus,1).
                eq(Product::getIsDeleted,0).
                eq(dto.getBrandId() != null && dto.getBrandId() != 0,Product::getBrandId,dto.getBrandId());

       return list(like);
    }
}
